import store from '@/store'
import { useEnvStore } from '@/store/env'
import { createI18n } from 'vue-i18n'
import zh_CN from './zh_CN'
import en_GB from './en_GB'
import ImageResources from './ImageResources'
import { PostRequest } from '@/utils/request'
import type { App } from 'vue'
import { getAnnouncement } from '@/api/common'
// let messages =
type MessageType = {
  zh_CN: unknown
  en: unknown
}
let messages: MessageType
const envStore = useEnvStore(store)

// 检测版本更新i18
export async function checkVersion(app: App<Element>) {
  const res = await getAnnouncement()
  let newMessage
  if (res.code == 0) {
    newMessage = {
      zh_CN: {
        ...ImageResources,
        'Navigator.My.GeneralSetting.Text': '通用一下',
      },
      en: en_GB,
    }
  } else {
    newMessage = {
      zh_CN,
      en: en_GB,
    }
  }
  const fixI18n = createI18n({
    locale: envStore.language,
    messages: newMessage,
    fallbackLocale: 'zh_CN',
    silentFallbackWarn: true,
  })
  // return fixI18n
  app.use(fixI18n)
}

let i18n = createI18n({
  locale: envStore.language,
  messages: {
    zh_CN,
    en: en_GB,
  },
  fallbackLocale: 'zh_CN',
  silentFallbackWarn: true,
})
// checkVersion()
